package com.hnucm.onlinealgstudy.controller;

import com.hnucm.onlinealgstudy.pojo.Comment;
import com.hnucm.onlinealgstudy.pojo.Recommend;
import com.hnucm.onlinealgstudy.pojo.StudiedAlg;
import com.hnucm.onlinealgstudy.pojo.User;
import com.hnucm.onlinealgstudy.service.AlgorithmService;
import com.hnucm.onlinealgstudy.utils.ResultOBJ;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

@RestController
@RequestMapping("/oasadapi/algorithms")
public class AlgorithmController {
    @Autowired
    AlgorithmService algorithmService;

    // 获取推荐算法
    @GetMapping
    public List<Recommend> getRecommendList(){
        return algorithmService.getRecommendedList();
    }
    // 浏览量加1
    @PostMapping(value ="/{id}")
    public ResultOBJ addViewNum(@PathVariable Integer id){
        try {
            algorithmService.addViewNum(id);
            return ResultOBJ.UPDATE_SUCCESS;
        } catch (Exception e) {
            return ResultOBJ.UPDATE_ERROR;
        }
    }
    // 添加已学算法
    @PostMapping
    public ResultOBJ addStudiedAlg(@RequestBody StudiedAlg studiedAlg){
        try {
            algorithmService.addStudiedAlg(studiedAlg);
            return ResultOBJ.ADD_SUCCESS;
        } catch (Exception e) {
            return ResultOBJ.ADD_ERROR;
        }
    }
    // 获取用户已学算法
    @GetMapping(value="/search")
    public List<StudiedAlg> getStudiedAlgList(String user_name){
        return algorithmService.getStudiedAlgList(user_name);
    }
}
